function returnDeleteFile(fID) {
	document.getElementById('fileRow'+fID).style.display = 'none';
}

function getRegistered(progID) {
	if (progID != '') {
		var eID = $('eID').value;
		x_getRegistered(progID,eID,returnGetRegistered);
	}
}

function returnGetRegistered(string) {
	if (string != '') {
		$('existingPeopleContainer').innerHTML = string;
		
		// Turn on label
		if ($('existingLabel').style.display == 'none') {
			$('existingLabel').style.display = 'block';
		}
	}	
}

function rowHoverControls(id,onOff,offClass) {
	var rowID     = 'row'+id;
	var controlID = 'control'+id;
	
	if (onOff == 'on') {
		$(rowID).className = 'hiLite';
	} else {
		$(rowID).className  = offClass;
	}	
}

function saveReg(doWhat,regUserID) {
	// First determine if we have a program selected yet
	var eID = $('eID').value;
	var programID = $('program').options;
	var programID = programID[programID.selectedIndex].value;
	if ( (programID == 'Select...') || (programID == '') ) {
		$('message').className = 'errorMessage';
		$('message').innerHTML = 'You must select a program first.';
		doFade(7,'message');
	} else {	
		if (doWhat == 'add') {
			var nameFirst = $('newNameFirst').value;
			var nameLast  = $('newNameLast').value;
			var phone     = $('newPhone').value;
			var email     = $('newEmail').value;
			var position  = $('newPosition').options;
			var position  = position[position.selectedIndex].value;
			var phpString = programID+'|'+nameFirst+'|'+nameLast+'|'+phone+'|'+email+'|'+position;
		} else {
			var nameFirst = $('nameFirst'+regUserID).value;
			var nameLast  = $('nameLast'+regUserID).value;
			var phone     = $('phone'+regUserID).value;
			var email     = $('email'+regUserID).value;
			var position  = $('position'+regUserID).options;
			var position  = position[position.selectedIndex].value;
			var emailHidden = $('emailHidden'+regUserID).value;
			var phpString = programID+'|'+nameFirst+'|'+nameLast+'|'+phone+'|'+email+'|'+position+'|'+emailHidden;
		}
		
		// More error checking
		if ( (nameFirst == 'First Name') || 
			 (nameLast == 'Last Name')  || 
			 (nameFirst == '') || 
			 (nameLast == '') ) {
			
			$('message').className = 'errorMessage';
			$('message').innerHTML = 'You must enter a First and Last Name.';
			doFade(7,'message');
		} else {	
			clearMessage();	
			x_saveReg(phpString,eID,doWhat,regUserID,returnSaveReg);
		}	
	}	
}

function returnSaveReg(string) {
	var stringArray = string.split('|');
	var content = stringArray[0];	
	var uID     = stringArray[1];	
	if (content != 'null') {		
		var newPersonDiv = document.createElement("div");
		newPersonDiv.id  = 'person'+uID;
		newPersonDiv.innerHTML = content;
		newPersonDiv.style.padding = '3px';
		var newPerson = $('newPerson');
		var registerPeopleContainer = $('registerPeopleContainer');
      	registerPeopleContainer.insertBefore(newPersonDiv,newPerson);
		
		// Clear form
		clearRegForm();
		
		// Turn on label
		if ($('existingLabel').style.display == 'none') {
			$('existingLabel').style.display = 'block';
		}
	}
	doFade(7,'person'+uID);		
}

function deleteReg(uID) {
	$('person'+uID).style.display = 'none';
	var eID = $('eID').value;
	x_deleteReg(uID,eID,returnDeleteReg);
}

function returnDeleteReg() {
	// Do nothing
}

function clearRegForm() {
	$('newNameFirst').value = 'First Name';
	$('newNameLast').value  = 'Last Name';
	$('newPhone').value     = 'Phone Number';
	$('newEmail').value     = 'Email Address';
	$('newPosition').options.selectedIndex = 0;
}

function clearMessage() {
	$('message').className = '';
	$('message').innerHTML = '';
}

function doFade(colorId, targetId) {
 	var FadeInterval = 300;
	var StartFadeAt  = 7;
	var FadeSteps = new Array();
		FadeSteps[1] = "ff";
		FadeSteps[2] = "ee";
		FadeSteps[3] = "dd";
		FadeSteps[4] = "cc";
		FadeSteps[5] = "bb";
		FadeSteps[6] = "aa";
		FadeSteps[7] = "99";
    if (colorId >= 1) {
		$(targetId).style.backgroundColor = "#ffff" + FadeSteps[colorId];
		
        // If it's the last color, set it to transparent
        if (colorId==1) {
            $(targetId).style.backgroundColor = "transparent";
		}
        colorId--;
		
        // Wait a little bit and fade another shade
        setTimeout("doFade("+colorId+",'"+targetId+"')", FadeInterval);
	}
} 

function editProgramAddress(programID) {
	$('tempProgramAddress').innerHTML = '';
	x_getProgramForEdit(programID,returnEditProgramAddress);
}

function returnEditProgramAddress(string) {
	var origAddress = $('addressContainer').innerHTML;
	$('tempProgramAddress').innerHTML = origAddress;
	$('addressContainer').innerHTML = string;
	$('editProgramAddress').style.display = 'none';
}

function cancelSaveProgramAddress() {
	$('addressContainer').innerHTML = $('tempProgramAddress').innerHTML;
	$('editProgramAddress').style.display = '';
}

function saveProgramAddress() {
	var pID      = $('pID').value;
	var pName    = $('pName').value;	
	var pCounty  = $('pCounty').value;
	var pAddress = $('pAddress').value;
	var pCity    = $('pCity').value;
	var pZip     = $('pZip').value;
	
	var phpString = pID+'|'+pName+'|'+pCounty+'|'+pAddress+'|'+pCity+'|'+pZip;
	x_saveProgramAddress(phpString,returnSaveProgramAddress);
}

function returnSaveProgramAddress(string) {
	$('editProgramAddress').style.display = '';
	$('tempProgramAddress').innerHTML = '';
	$('addressContainer').innerHTML = string;
}

function editProgramContact(uID) {
	var contactDetails = $('contactContainer'+uID).innerHTML;
	$('contactContainerTemp'+uID).innerHTML = contactDetails;
	x_getContactForEdit(uID,returnEditProgramContact);
}

function cancelEditProgramContact(uID) {
	var divID = 'contactContainerTemp'+uID;
	var origContent = $(divID).innerHTML;
	$('contactContainer'+uID).innerHTML = origContent;
	$(divID).innerHTML = '';
}

function returnEditProgramContact(string) {	
	var stringArray = string.split('|');
	var divContent = stringArray[0];
	var uID = stringArray[1];
	$('contactContainer'+uID).innerHTML = divContent;
}

function saveProgramContact(uID) {
	var nameFirst = $('nameFirst'+uID).value;
	var nameLast  = $('nameLast'+uID).value;
	var programID = $('programID'+uID).options;
	var programID = programID[programID.selectedIndex].value;
	var email     = $('email'+uID).value;
	var phone1    = $('phone1'+uID).value;
	var phone2    = $('phone2'+uID).value;
	var officeNo  = $('officeNo'+uID).value;
	var positionID= $('positionID'+uID).options;
	var positionID= positionID[positionID.selectedIndex].value;
	var phpString =  uID+'|'+nameFirst+'|'+nameLast+'|'+programID+'|'+email+'|';
	phpString += phone1+'|'+phone2+'|'+officeNo+'|'+positionID;
	x_saveProgramContact(phpString,returnSaveProgramContact);
}

function returnSaveProgramContact(string) {
	var stringArray = string.split('|');
	var divContent = stringArray[0];
	var uID = stringArray[1];
	$('contactContainer'+uID).innerHTML = divContent;
}

function returnDeleteProgramContact(uID) {
	var contactDiv = $('contactContainer'+uID);
	Effect.Fade(contactDiv, {delay: .1, duration: 1});
}